package hanjia;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/15-下午1:31
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode491 {

    public List<List<Integer>> findSubsequences(int[] nums) {
        int start = 0;
        List<Integer> result = new ArrayList<>();
        List<List<Integer>> results = new ArrayList<>();


        backtracking(start, result, results, nums);
        return results;


    }

    private void backtracking(int start, List<Integer> result, List<List<Integer>> results, int[] nums) {

        if (result.size()>=2){
            results.add(new ArrayList<>(result));

        }
        if (start>=nums.length){
            return;
        }

        HashSet<Integer> used = new HashSet<>();
        for (int i = start; i < nums.length; i++) {
            if (used.contains(nums[i])) {
                continue;
            }

         if (result.size()==0||result.get(result.size()-1)<=nums[i]){
             used.add(nums[i]);
             result.add(nums[i] );
             backtracking(i+1,result,results,nums);
             result.remove(result.size()-1);
         }


        }


    }

    public static void main(String[] args) {
        int []nums={4,6,7,7};
        LeetCode491 leetCode491 = new LeetCode491();
        System.out.println(leetCode491.findSubsequences(nums));
    }


}
